import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 高生平
 * Date: 2025-09-01
 * Time: 21:10
 */

//编写代码模拟三次密码输入的场景。
//最多能输入三次密码，密码正确，提示“登录成功”,
//密码错误,可以重新输入，最多输入三次。三次均错，则提示退出程序
public class Test {
    public static void main(String[] args) {
        int password = 202596;
        Scanner sc = new Scanner(System.in);
        int count = 0;
        System.out.println("请输入密码");
        while(count < 3) {
            int login = sc.nextInt();
            if (login == password) {
                System.out.println("登录成功");
                break;
            } else {
                count++;
                int chances = 3 - count;
                if (count < 3) {
                    System.out.println("密码错误，请重新输入(还剩" + chances + "次机会)");
                }
            }
            if (count == 3) {
                System.out.println("退出程序");
            }
        }
    }
}
